package com.itcncp.common.util;
import com.itcncp.common.model.XianxingModels;
import com.itcncp.common.rongCloud.models.SdkHttpResult;
import com.itcncp.common.rongCloud.models.XianxingHttpResult;
import com.itcncp.common.rongCloud.util.HttpUtil;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;

public class CarBrandUtils {
	
	private static final String url = "http://api.jisuapi.com/car";
	
	private static final String appkey = "1d5a8e50fc75b0c5";

	/**
	 * 获取所有品牌
	 * @param
	 * @return
	 */
	public static SdkHttpResult getBrand()  {

		HttpURLConnection conn;
		try {
			conn = HttpUtil.CreatePostHttpConnection("", "", url+"/brand" );

			StringBuilder sb = new StringBuilder();
			sb.append("&appkey=").append(appkey);

			HttpUtil.setBodyParameter(sb, conn);

			SdkHttpResult sdkHttpResult  = HttpUtil.returnResult( conn );

			return sdkHttpResult;
		} catch (IOException e) {
			e.printStackTrace();
			return  null;
		} catch (Exception e) {
			e.printStackTrace();
			return  null;
		}
	}
	/**
	 * 根据车型获取车
	 * @param
	 * @return
	 */
	public static SdkHttpResult getCar(String parentid)  {

		HttpURLConnection conn;
		try {
			conn = HttpUtil.CreatePostHttpConnection("", "", url+"/car" );

			StringBuilder sb = new StringBuilder();
			sb.append("&parentid=").append(parentid);
			sb.append("&appkey=").append(appkey);

			HttpUtil.setBodyParameter(sb, conn);

			SdkHttpResult sdkHttpResult  = HttpUtil.returnResult( conn );

			return sdkHttpResult;
		} catch (IOException e) {
			e.printStackTrace();
			return  null;
		} catch (Exception e) {
			e.printStackTrace();
			return  null;
		}
	}

	/**
	 * 根据品牌获取车型
	 * @param
	 * @return
	 */
	public static SdkHttpResult getCarType(String parentid)  {

		HttpURLConnection conn;
		try {
			conn = HttpUtil.CreatePostHttpConnection("", "", url+"/type" );

			StringBuilder sb = new StringBuilder();
			sb.append("&parentid=").append(parentid);
			sb.append("&appkey=").append(appkey);

			HttpUtil.setBodyParameter(sb, conn);

			SdkHttpResult sdkHttpResult  = HttpUtil.returnResult( conn );

			return sdkHttpResult;
		} catch (IOException e) {
			e.printStackTrace();
			return  null;
		} catch (Exception e) {
			e.printStackTrace();
			return  null;
		}
	}

}
